﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TravelLink.WebModel;
using TravelLink.Common;

namespace TravelLink.WebApp.UserControl.Register {
    public partial class UC_ForgetPassword : ControlBase {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void btnSubmit_Click(object sender, ImageClickEventArgs e) {
            string email = WebHelper.GetFormStr("email", "").ToUpper();

            if (!string.IsNullOrEmpty(email)) {
                var entity = this.DB.TL_User.Where(u => u.Email.ToUpper() == email).FirstOrDefault();
                if (entity != null) {
                    string newPwd = MailSender.SendMailByForgetPassword(entity.UserCode, entity.Email);
                    if (!string.IsNullOrEmpty(newPwd)) {
                        entity.Password = newPwd;
                        this.DB.SubmitChanges();
                        Response.Redirect("ForgetSuccess.aspx");//System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("",)
                    }
                }
            }
        }
    }
}